{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from tinysmpc import VirtualMachine, PrivateScalar, SharedScalar\n",
    "from tinysmpc.fixed_point import fixed_point, float_point\n",
    "from tinysmpc.finite_ring import MAX_INT64, MIN_INT64\n",
    "from tinysmpc.secret_sharing import Share"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test Reconstruction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Reconstruction of PrivateScalar -> SharedScalar -> PrivateScalar\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = PrivateScalar(123456, alice)\n",
    "b = PrivateScalar(-123456, bob)\n",
    "\n",
    "a_shared = a.share([alice, bob, charlie])\n",
    "b_shared = b.share([alice, bob, charlie])\n",
    "\n",
    "a_rec = a_shared.reconstruct(alice)\n",
    "b_rec = b_shared.reconstruct(bob)\n",
    "\n",
    "assert a_rec.value == 123456 and b_rec.value == -123456"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Reconstruction of PrivateScalar -> SharedScalar -> PrivateScalar in a small prime ring\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = PrivateScalar(13, alice)\n",
    "a_shared = a.share([alice, bob, charlie], Q=67)\n",
    "\n",
    "a_rec = a_shared.reconstruct(alice)\n",
    "\n",
    "assert a_rec.value == 13"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test Addition"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Addition of SharedScalars\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = PrivateScalar(100, alice)\n",
    "b = PrivateScalar(120, bob)\n",
    "c = PrivateScalar(-40, charlie)\n",
    "\n",
    "a_shared = a.share([alice, bob, charlie])\n",
    "b_shared = b.share([alice, bob, charlie])\n",
    "c_shared = c.share([alice, bob, charlie])\n",
    "\n",
    "res_shared = a_shared + b_shared + c_shared\n",
    "res = res_shared.reconstruct(alice)\n",
    "\n",
    "assert res.value == 180"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Addition of SharedScalar and a public integer\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = PrivateScalar(120, alice)\n",
    "a_shared = a.share([alice, bob, charlie])\n",
    "\n",
    "res_shared = 100 + a_shared + (-90)\n",
    "res = res_shared.reconstruct(alice)\n",
    "\n",
    "assert res.value == 130"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Addition of SharedScalars in a small prime ring\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = PrivateScalar(12, alice)\n",
    "b = PrivateScalar(10, bob)\n",
    "\n",
    "a_shared = a.share([alice, bob, charlie], Q=67)\n",
    "b_shared = b.share([alice, bob, charlie], Q=67)\n",
    "\n",
    "res_shared = a_shared + b_shared\n",
    "res = res_shared.reconstruct(alice)\n",
    "\n",
    "assert res.value == 22"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Addition of SharedScalar and a public integer in a small prime ring\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = PrivateScalar(12, alice)\n",
    "a_shared = a.share([alice, bob, charlie], Q=67)\n",
    "\n",
    "res_shared = 10 + a_shared + (-4)\n",
    "res = res_shared.reconstruct(alice)\n",
    "\n",
    "assert res.value == 18"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test Subtraction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Subtraction of SharedScalars\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = PrivateScalar(1200, alice)\n",
    "b = PrivateScalar(100, bob)\n",
    "c = PrivateScalar(-20, charlie)\n",
    "\n",
    "a_shared = a.share([alice, bob, charlie])\n",
    "b_shared = b.share([alice, bob, charlie])\n",
    "c_shared = c.share([alice, bob, charlie])\n",
    "\n",
    "res_shared = a_shared - b_shared - c_shared\n",
    "res = res_shared.reconstruct(alice)\n",
    "\n",
    "assert res.value == 1120"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Subtraction of SharedScalar and a public integer\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = PrivateScalar(1200, alice)\n",
    "a_shared = a.share([alice, bob, charlie])\n",
    "\n",
    "res_shared = 2400 - a_shared - (-100)\n",
    "res = res_shared.reconstruct(alice)\n",
    "\n",
    "assert res.value == 1300"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Subtraction of SharedScalars in a small prime ring\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = PrivateScalar(12, alice)\n",
    "b = PrivateScalar(10, bob)\n",
    "\n",
    "a_shared = a.share([alice, bob, charlie], Q=67)\n",
    "b_shared = b.share([alice, bob, charlie], Q=67)\n",
    "\n",
    "res_shared = a_shared - b_shared\n",
    "res = res_shared.reconstruct(alice)\n",
    "\n",
    "assert res.value == 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Subtraction of SharedScalar and a public integer in a small prime ring\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = PrivateScalar(10, alice)\n",
    "a_shared = a.share([alice, bob, charlie], Q=67)\n",
    "\n",
    "res_shared = 12 - a_shared - (-4)\n",
    "res = res_shared.reconstruct(alice)\n",
    "\n",
    "assert res.value == 6"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test Multiplication"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Multiplication of SharedScalars\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = PrivateScalar(120, alice)\n",
    "b = PrivateScalar(130, bob)\n",
    "c = PrivateScalar(-2, charlie)\n",
    "\n",
    "a_shared = a.share([alice, bob, charlie])\n",
    "b_shared = b.share([alice, bob, charlie])\n",
    "c_shared = c.share([alice, bob, charlie])\n",
    "\n",
    "res_shared = a_shared * b_shared * c_shared\n",
    "res = res_shared.reconstruct(alice)\n",
    "\n",
    "assert res.value == -31200"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Multiplication of SharedScalar and a public integer\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = PrivateScalar(120, alice)\n",
    "a_shared = a.share([alice, bob, charlie])\n",
    "\n",
    "res_shared = 130 * a_shared * (-2)\n",
    "res = res_shared.reconstruct(alice)\n",
    "\n",
    "assert res.value == -31200"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Multiplication of SharedScalars in a small prime ring\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = PrivateScalar(5, alice)\n",
    "b = PrivateScalar(4, bob)\n",
    "\n",
    "a_shared = a.share([alice, bob, charlie], Q=67)\n",
    "b_shared = b.share([alice, bob, charlie], Q=67)\n",
    "\n",
    "res_shared = a_shared * b_shared\n",
    "res = res_shared.reconstruct(alice)\n",
    "\n",
    "assert res.value == 20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Multiplication of SharedScalar and a public integer in a small prime ring\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = PrivateScalar(5, alice)\n",
    "a_shared = a.share([alice, bob, charlie], Q=67)\n",
    "\n",
    "res_shared = 4 * a_shared * (-1)  # This product (-20) is not representable in a prime field, and will be modulo'ed to 54 (== -20 % 67)\n",
    "res = res_shared.reconstruct(alice)\n",
    "\n",
    "assert res.value == 47"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test Exponents"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "def test_pow(x, n):\n",
    "    alice = VirtualMachine('alice')\n",
    "    bob = VirtualMachine('bob')\n",
    "    x_sh = PrivateScalar(x, alice).share([alice, bob])\n",
    "    assert (x_sh**n).reconstruct(alice).value == (x**n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_pow(2, 1)\n",
    "test_pow(2, 2)\n",
    "test_pow(2, 3)\n",
    "test_pow(2, 62)  # Max that fits as an int64"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test Compare"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "def test_compare(x, r):  \n",
    "    alice = VirtualMachine('alice')\n",
    "    bob = VirtualMachine('bob')\n",
    "    x_sh = PrivateScalar(x, alice).share([alice, bob])\n",
    "    assert (x_sh > r).value == (x > r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_compare(1, 0)\n",
    "test_compare(200, 100)\n",
    "test_compare(100, 100)\n",
    "test_compare(100, 200)\n",
    "test_compare(MAX_INT64, MAX_INT64)\n",
    "test_compare(MIN_INT64, MIN_INT64)\n",
    "test_compare(MIN_INT64, MAX_INT64)\n",
    "test_compare(MAX_INT64, MIN_INT64)\n",
    "test_compare(100, -100)\n",
    "test_compare(-100, 100)\n",
    "test_compare(-100, -200)\n",
    "test_compare(-200, -100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test Floats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Reconstruction of PrivateScalar (float) -> SharedScalar -> PrivateScalar (float)\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = fixed_point(123.456)\n",
    "b = fixed_point(-123.456)\n",
    "a = PrivateScalar(a, alice)\n",
    "b = PrivateScalar(b, bob)\n",
    "\n",
    "a_shared = a.share([alice, bob, charlie])\n",
    "b_shared = b.share([alice, bob, charlie])\n",
    "\n",
    "a_rec = float_point(a_shared.reconstruct(alice).value)\n",
    "b_rec = float_point(b_shared.reconstruct(bob).value)\n",
    "\n",
    "assert a_rec == 123.456 and b_rec == -123.456"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Addition of SharedScalars (float)\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = fixed_point(1.01)\n",
    "b = fixed_point(1.02)\n",
    "c = fixed_point(-2.01)\n",
    "a = PrivateScalar(a, alice)\n",
    "b = PrivateScalar(b, bob)\n",
    "c = PrivateScalar(c, charlie)\n",
    "\n",
    "a_shared = a.share([alice, bob, charlie])\n",
    "b_shared = b.share([alice, bob, charlie])\n",
    "c_shared = c.share([alice, bob, charlie])\n",
    "\n",
    "res_shared = a_shared + b_shared + c_shared\n",
    "res = float_point(res_shared.reconstruct(alice).value)\n",
    "\n",
    "EPS = 10**-8\n",
    "assert abs(res - (1.01 + 1.02 + -2.01)) < EPS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Multiplication of SharedScalars (float)\n",
    "\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "charlie = VirtualMachine('charlie')\n",
    "\n",
    "a = fixed_point(2.5)\n",
    "b = fixed_point(-5.1)\n",
    "a = PrivateScalar(a, alice)\n",
    "b = PrivateScalar(b, bob)\n",
    "\n",
    "a_shared = a.share([alice, bob, charlie])\n",
    "b_shared = b.share([alice, bob, charlie])\n",
    "\n",
    "res_shared = a_shared * b_shared\n",
    "res = float_point(res_shared.reconstruct(alice).value, n_mults=1)\n",
    "\n",
    "EPS = 10**-7\n",
    "assert abs(res - (2.5 * -5.1)) < EPS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Comparison of a SharedScalar (float) and a public float\n",
    "alice = VirtualMachine('alice')\n",
    "bob = VirtualMachine('bob')\n",
    "\n",
    "x = fixed_point(-1.14)\n",
    "r = fixed_point(-1.15)\n",
    "\n",
    "x_sh = PrivateScalar(x, alice).share([alice, bob])\n",
    "\n",
    "assert (x_sh > r).value == (x > r)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test Asserts "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Cannot share a PrivateScalar with duplicate VirtualMachines\n",
    "\n",
    "def test_assert():\n",
    "    alice = VirtualMachine('alice')\n",
    "    bob = VirtualMachine('bob')\n",
    "\n",
    "    a = PrivateScalar(10, alice)\n",
    "\n",
    "    try: a.share([bob, bob])\n",
    "    except AssertionError as e: return True\n",
    "    \n",
    "assert test_assert()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9223372036854775808 is not an int64 and cannot be reconstructed. Use a smaller value.\n"
     ]
    }
   ],
   "source": [
    "# Cannot share an int64 that is too large\n",
    "\n",
    "def test_assert():\n",
    "    alice = VirtualMachine('alice')\n",
    "    bob = VirtualMachine('bob')\n",
    "\n",
    "    MAX_INT64 = 9223372036854775807\n",
    "    a = PrivateScalar(MAX_INT64 + 1, alice)\n",
    "\n",
    "    try: a.share([alice, bob])\n",
    "    except AssertionError as e: print(e); return True\n",
    "    \n",
    "assert test_assert()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-1 does not fit inside a size-67 prime ring, so it cannot be split into shares that can be reconstructed. Use a larger Q or a smaller value.\n"
     ]
    }
   ],
   "source": [
    "# Cannot share an int that is too large for the prime ring\n",
    "\n",
    "def test_assert():\n",
    "    alice = VirtualMachine('alice')\n",
    "    bob = VirtualMachine('bob')\n",
    "\n",
    "    a = PrivateScalar(-1, alice)\n",
    "\n",
    "    try: a.share([alice, bob], Q=67)\n",
    "    except AssertionError as e: print(e); return True\n",
    "    \n",
    "assert test_assert()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9223372036854775808 is not an int64 and cannot be reconstructed. Use a smaller value.\n"
     ]
    }
   ],
   "source": [
    "# Cannot create a Share that is over an int64\n",
    "\n",
    "def test_assert():\n",
    "    alice = VirtualMachine('alice')\n",
    "    \n",
    "    MAX_INT64 = 9223372036854775807\n",
    "    try: Share(MAX_INT64 + 1, alice)\n",
    "    except AssertionError as e: print(e); return True\n",
    "\n",
    "assert test_assert()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-1 does not fit inside a size-67 prime ring, so it cannot be split into shares that can be reconstructed. Use a larger Q or a smaller value.\n"
     ]
    }
   ],
   "source": [
    "# Cannot create a Share that is too large for the prime ring\n",
    "\n",
    "def test_assert():\n",
    "    alice = VirtualMachine('alice')\n",
    "    \n",
    "    try: Share(-1, alice, Q=67)\n",
    "    except AssertionError as e: print(e); return True\n",
    "\n",
    "assert test_assert()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Share(6707471470770242043, 'alice', Q=None) and Share(-6707471470770242038, 'bob', Q=None) do not have the same owners.\n"
     ]
    }
   ],
   "source": [
    "# Cannot add Shares on different VirtualMachines\n",
    "\n",
    "def test_assert():\n",
    "    alice = VirtualMachine('alice')\n",
    "    bob = VirtualMachine('bob')\n",
    "\n",
    "    a = PrivateScalar(5, alice)\n",
    "\n",
    "    a_shared = a.share([alice, bob])\n",
    "    \n",
    "    try: a_shared.share_of[alice] + a_shared.share_of[bob]\n",
    "    except AssertionError as e: print(e); return True\n",
    "\n",
    "assert test_assert()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SharedScalar\n",
      " - Share(4396492157189063946, 'alice', Q=None)\n",
      " - Share(-4396492157189063941, 'bob', Q=None)\n",
      "and\n",
      "SharedScalar\n",
      " - Share(3, 'alice', Q=67)\n",
      " - Share(7, 'bob', Q=67)\n",
      "are not over the same rings.\n"
     ]
    }
   ],
   "source": [
    "# Cannot add Shares on different fields\n",
    "\n",
    "def test_assert():\n",
    "    alice = VirtualMachine('alice')\n",
    "    bob = VirtualMachine('bob')\n",
    "\n",
    "    a = PrivateScalar(5, alice)\n",
    "    b = PrivateScalar(10, bob)\n",
    "\n",
    "    a_shared = a.share([alice, bob])\n",
    "    b_shared = b.share([alice, bob], Q=67)\n",
    "    \n",
    "    try: a_shared + b_shared\n",
    "    except AssertionError as e: print(e); return True\n",
    "\n",
    "assert test_assert()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Share(-2429788824100047652, 'alice', Q=None) and Share(2429788824100047657, 'bob', Q=None) do not have the same owners.\n"
     ]
    }
   ],
   "source": [
    "# Cannot multiply Shares on different VirtualMachines\n",
    "\n",
    "def test_assert():\n",
    "    alice = VirtualMachine('alice')\n",
    "    bob = VirtualMachine('bob')\n",
    "\n",
    "    a = PrivateScalar(5, alice)\n",
    "\n",
    "    a_shared = a.share([alice, bob])\n",
    "    \n",
    "    try: a_shared.share_of[alice] * a_shared.share_of[bob]\n",
    "    except AssertionError as e: print(e); return True\n",
    "\n",
    "assert test_assert()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SharedScalar\n",
      " - Share(1780098893906485608, 'alice', Q=None)\n",
      " - Share(-1780098893906485603, 'bob', Q=None)\n",
      "and\n",
      "SharedScalar\n",
      " - Share(23, 'alice', Q=67)\n",
      " - Share(54, 'bob', Q=67)\n",
      "are not over the same rings.\n"
     ]
    }
   ],
   "source": [
    "# Cannot multiply Shares on different fields\n",
    "\n",
    "def test_assert():\n",
    "    alice = VirtualMachine('alice')\n",
    "    bob = VirtualMachine('bob')\n",
    "\n",
    "    a = PrivateScalar(5, alice)\n",
    "    b = PrivateScalar(10, bob)\n",
    "\n",
    "    a_shared = a.share([alice, bob])\n",
    "    b_shared = b.share([alice, bob], Q=67)\n",
    "    \n",
    "    try: a_shared * b_shared\n",
    "    except AssertionError as e: print(e); return True\n",
    "\n",
    "assert test_assert()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
